//作者860563585
//项目地址https://gitee.com/HanaHimeUnica/yzjs
//该版本为二改，修改者@玖
import plugin from '../../lib/plugins/plugin.js'
import common from "../../lib/common/common.js"
export class srexchange extends plugin {
    constructor() {
        super({
            name: '米家四游资源预估(取图版)',
            dsc: '预估',
            event: 'message',
            priority: -11451411,
            rule: [
                {
                    reg: '^#?((原神|原石|gs)|(星铁|星琼|sr)|(崩坏三|崩三|水晶|bbb|bh3|bhs)|(绝区零|绝区|菲林|邦布券|邦布|zzz))(预估|盘点)$',
                    fnc: "mysEstimate"
                }
            ]
        })
    }

    async mysEstimate(e) {
        let api = "https://bbs-api.miyoushe.com/painter/api/user_instant/search/list?keyword="
        let size = "20"//条数
        let sort_type = "2"//排序
        let args = []
        /* 
        结构 ['原石统计汇总', 137101761, 3] 
        ['帖子标题关键字段', 作者uid, 帖子内的第几张图片从0开始计数] 0是第1张图，1是第2张图，2是第3张图......以此类推

        如果只选择  神鱼  作者，请保留上下版本 2 行代码

        */
        if (/原神|原石|gs/.test(this.e.msg)) {
            this.reply(`原石统计获取中，请稍后...`);
            args = [
                ['原石统计汇总', 137101761, 3] /* 祈鸢ya https://www.miyoushe.com/ys/accountCenter/postList?id=137101761 */,
                ['原石资源统计', 285802042, 1] /* HoYo青枫 https://www.miyoushe.com/ys/accountCenter/postList?id=285802042 */,
            /*上版本统计*/['原石统计', 11506953, 1] /* 神鱼 https://www.miyoushe.com/ys/accountCenter/postList?id=11506953 */,
            /*下版本统计*/['原石统计', 11506953, 0] /* 神鱼 https://www.miyoushe.com/ys/accountCenter/postList?id=11506953 */,
                ['原石获取统计', 286192908, 1] /* 弃剑不负你 https://www.miyoushe.com/ys/accountCenter/postList?id=286192908 */,
            /*【断更】*/['原石统计', 282482912] /* 杨家小羊蹄 https://www.miyoushe.com/ys/accountCenter/postList?id=282482912 */,
            ]
        }
        if (/星铁|星琼|sr/.test(this.e.msg)) {
            this.reply(`星琼统计获取中，请稍后...`);
            args = [
                ['星琼统计汇总', 137101761, 3] /* 祈鸢ya https://www.miyoushe.com/ys/accountCenter/postList?id=137101761 */,
            /*上版本统计*/['星琼统计', 11506953, 1] /* 神鱼 https://www.miyoushe.com/ys/accountCenter/postList?id=11506953 */,
            /*下版本统计*/['星琼统计', 11506953, 0] /* 神鱼 https://www.miyoushe.com/ys/accountCenter/postList?id=11506953 */,
                ['星琼资源统计', 285802042, 1] /* HoYo青枫 https://www.miyoushe.com/ys/accountCenter/postList?id=285802042 */,
                ['星琼统计', 368830308, 0] /* 星穹中心 https://www.miyoushe.com/ys/accountCenter/postList?id=368830308 */,
                ['星琼统计', 286192908, 1] /* 弃剑不负你 https://www.miyoushe.com/ys/accountCenter/postList?id=286192908 */,
                ['星琼统计', 189288059, 1] /* 汐沐KN https://www.miyoushe.com/ys/accountCenter/postList?id=189288059 */,
            ]
        }
        if (/绝区零|绝区|菲林|邦布券|邦布|zzz/.test(this.e.msg)) {
            this.reply(`菲林统计获取中，请稍后...`);
            args = [
                ['菲林统计', 137101761, 2] /* 祈鸢ya https://www.miyoushe.com/ys/accountCenter/postList?id=137101761 */,
                ['抽数超细统计', 75596302, 2] /* 紫喵Azunya https://www.miyoushe.com/ys/accountCenter/postList?id=75596302 */,
            /*上版本统计*/['抽数统计', 11506953, 1] /* 神鱼 https://www.miyoushe.com/ys/accountCenter/postList?id=11506953 */,
            /*下版本统计*/['抽数统计', 11506953, 0] /* 神鱼 https://www.miyoushe.com/ys/accountCenter/postList?id=11506953 */,
                ['菲林资源统计', 285802042, 2] /* HoYo青枫 https://www.miyoushe.com/ys/accountCenter/postList?id=285802042 */,
                ['菲林统计', 5700838, 1] /* 墨小菊ぃ https://www.miyoushe.com/ys/accountCenter/postList?id=5700838 */,
            ]
        }
        if (/崩坏三|崩三|水晶|bbb|bh3|bhs/.test(this.e.msg)) {
            this.reply(`水晶统计获取中，请稍后...`);
            args = [
                ['水晶统计', 80216695, 0] /* 五香麻辣小兔头 https://www.miyoushe.com/ys/accountCenter/postList?id=80216695 */,
                ['水晶量', 51369902, 0] /* 酉年未月昴日 https://www.miyoushe.com/ys/accountCenter/postList?id=51369902 */,
            ]
        }
        //  let res = await (await fetch(`${api}${encodeURI(args[i][0])}&uid=${encodeURI(args[i][1])}&size=${size}&offset=0&sort_type=${sort_type}`)).json()
        //  let Estimate = res.data.list[0].post.post.images
        //  let img = Estimate[args[i][2]];
        //  if (!img) return

        let msg = [];
        for (let i = 0; i < args.length; i++) {
            let res = await (await fetch(`${api}${encodeURI(args[i][0])}&uid=${encodeURI(args[i][1])}&size=${size}&offset=0&sort_type=${sort_type}`)).json();
            let Estimate = res.data.list[0].post.post.images;
            let img = Estimate[args[i][2]];
            if (img) {
                msg.push([res.data.list[0].post.post.subject, segment.image(img)]);
            }
        }
        if (msg.length > 0) {
            await this.reply(common.makeForwardMsg(e, msg, `资源统计来啦~  \n如果出现图片错误，请忽略`));
        }
        return true;
    }
}
